<?php

if (!$listid) {
    $to = 'index.php?cmd=login';
    header('Location: ' . $to);
}
?>

<?php

$color01 = "4d4e66";
$color02 = "#d8d8f0";
$color03 = "#cccccc";

mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
if ($listid == 4) {
    $sqlquery = "select * from $TSendSMS order by SMSId desc Limit 0, 200";
} else {
    $sqlquery = "select * from $TSendSMS where ListId = '$listid' order by SMSId desc Limit 0, 200";
}
$results = mysql_query($sqlquery) or die("Unable to query : " . mysql_error());

// Printer resultatet i HTML
echo "<table width='960'>\n";
echo "\t<tr bgcolor='$color01' style='color:#ffffff; font-weight:bold;'>\n";
echo "\t\t<td>Mobil</td>\n";
echo "\t\t<td>Besked</td>\n";
echo "\t\t<td>Status</td>\n";
echo "\t\t<td>Dato</td>\n";
echo "\t\t<td>Id</td>\n";
echo "\t\t<td style='text-align: center;'><a href='../../smsdeleteall.php?listid=$listid&phone=$fromphone' style='color:#ffffff; font-weight:bold;'>Slet alle</a></td>\n";
echo "\t</tr>\n";

while ($line = mysql_fetch_array($results, MYSQL_ASSOC)) {
    if ($color == $color03) {
        $color = $color02;
    } else {
        $color = $color03;
    }

    $smsid = $line["SMSId"];
    $cellphone = $line["CellPhone"];
    $message = $line["Message"];
    $status = $line["Status"];
    $date = $line["Date"];
    $filename = $line["ListId"];
    if (!$status) {
        $status = "Waiting";
    }

    echo "\t<tr bgcolor='$color'>\n";
    echo "\t\t<td>$cellphone</td>\n";
    echo "\t\t<td>$message</td>\n";
    echo "\t\t<td>$status</td>\n";
    echo "\t\t<td>$date</td>\n";
    echo "\t\t<td>$filename</td>\n";
    echo "\t\t<td style='text-align: center;'><a href='../../smsdelete.php?listid=$listid&phone=$fromphone&smsid=$smsid' class='list'>delete</a></td>\n\t</tr>\n";
}
echo "</table>\n";

mysql_free_result($results);
mysql_close();
?>